<?php

/**
 * Ctdocumentocaracteristica form.
 *
 * @package    ingenyo-biblio
 * @subpackage form
 * @author     Your name here
 */
class CtDocumentoCaracteristicaTipificadoForm extends BaseCtdocumentocaracteristicaForm
{

  public function configure()
  {

    unset($this['ValorTipificacion'], $this['usuario'], $this['fechaCambio']);
    unset($this['idDocumento']);
    
    $this->setWidget('idIteracion', new sfWidgetFormInputHidden());
    $sf_formatter_revisited = new documentoCaracteristicaFormatter($this->getWidgetSchema());
    $this->getWidgetSchema()->addFormFormatter("documentoCaracteristica", $sf_formatter_revisited);
    $this->getWidgetSchema()->setFormFormatterName("documentoCaracteristica");

    $documento_caracteristica = $this->getObject();
    $caracterisitica = $documento_caracteristica->getCtCaracteristica();
    $id_tipificacion = $caracterisitica->getIdtipificacion();
    $c = new Criteria();
    $c->add(CtValoresTipificacionPeer::IDTIPIFICACION, $id_tipificacion);
    $c->clearSelectColumns();
    $c->addSelectColumn(CtValoresTipificacionPeer::IDVALOR);
    $stmt = CtValoresTipificacionPeer::doSelectStmt($c);
    $id_valores = $stmt->fetchAll(PDO::FETCH_COLUMN);

    $c = new Criteria();
    $c->add(CtValoresPeer::IDVALOR, $id_valores, Criteria::IN);
    $valores = CtValoresPeer::doSelect($c);
    $choice = array();
    /* @var $valor CtValores */
    foreach ($valores as $valor)
    {
      $choice[$valor->getDescripcionvalor()] = $valor->getDescripcionvalor();
      #Asi deberia ser pero  ellos no usan las bases de datos relacionales
      #$choice[$valor->getIdvalor()] = $valor->getDescripcionvalor();
    }
    #var_dump($choice);



    $this->setWidget('valorCaracteristica', new sfWidgetFormChoice(array('choices' => $choice,'renderer_class' =>'mbWidgetFormChosenChoice')));
    $this->setWidget('idCaracteristica', new sfWidgetFormInputHidden());
    $caracteristica = $this->getObject()->getCtCaracteristica();


    $this->getValidator('valorCaracteristica')->setOption('required', $caracteristica->getRequeridacaracteristica());
    #$this->getWidget('valorCaracteristica')->setAttribute('required', $caracteristica->getRequeridacaracteristica());
    $this->getWidget('valorCaracteristica')->setAttribute('repetible', $caracteristica->getRepetiblecaracteristica());
    $this->getWidget('valorCaracteristica')->setLabel($caracteristica->getDescripcioncaracteristica());
    $this->getWidget('valorCaracteristica')->setDefault($this->getObject()->getValorcaracteristica());
    #esto si se guarda usando la base de forma relacional
    #$this->getWidget('valorCaracteristica')->setDefault($this->getObject()->getValorcaracteristicaTipificada());
    $this->validatorSchema->setOption('allow_extra_fields', true);
    $this->disableLocalCSRFProtection();

  }

}